package graduate.wangyaqi.QuestionDetail;

import graduate.wangyaqi.Question.Question;
import graduate.wangyaqi.Question.QuestionRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.Optional;

@Service
public class QuestionDetailService {
    @Resource
    private QuestionDetailRepository questionDetailRepository;

    //保存数据
    @Transactional
    public void save(QuestionDetail question) {
        questionDetailRepository.save(question);
    }

    //删除数据
    @Transactional
    public void delete(long id) {
        questionDetailRepository.deleteById(id);
    }

    //查询数据
    @Transactional
    public Iterable<QuestionDetail> getAll() {
        Iterable<QuestionDetail> questions = questionDetailRepository.findAll();
        return questions;
    }

    @Transactional
    public Iterable<QuestionDetail> findQuestionDetailByQuestionId(Long questionId) {
        Iterable<QuestionDetail> questions = questionDetailRepository.findQuestionDetailByQuestionIdOrderByAnswerTimeDesc(questionId);
        return questions;
    }
    @Transactional
    public Optional<QuestionDetail> findById(Long aLong){
        return questionDetailRepository.findById(aLong);
    };
}
